package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.activity.AuctionAddRemind_Activity;
import artid.com.arttogo.bean.SpecialInfoParser;
import artid.com.arttogo.bean.SpecialListParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;

/**
 * 
 *    
 * 项目名称：ArtworkArt   
 * 类名称：AuctionInfo_Adapter   
 * 类描述：拍卖会详情适配器   
 * 创建人：耿卫斌   
 * 创建时间：2017-3-2 下午5:32:44   
 *
 */
public class AuctionInfo_Adapter extends BaseAdapter {
	private Context mContext;
	private List<SpecialListParser> list;

	public AuctionInfo_Adapter(Context mContext, List<SpecialListParser> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	public void notifyData(List<SpecialListParser> list){
		this.list = list;
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_auctioninfo, null);
			holder.img=(ImageView) v.findViewById(R.id.itemAuctionInfo_img);
			holder.state=(TextView) v.findViewById(R.id.itemAuctionInfo_state);
			holder.title=(TextView) v.findViewById(R.id.itemAuctionInfo_title);
			holder.previewTime=(TextView) v.findViewById(R.id.itemAuctionInfo_PreviewTime);
			holder.num=(TextView) v.findViewById(R.id.itemAuctionInfo_num);
			holder.company=(TextView) v.findViewById(R.id.itemAuctionInfo_company);
			holder.address=(TextView) v.findViewById(R.id.itemAuctionInfo_address);
			holder.addRemind=(TextView) v.findViewById(R.id.itemAuctionInfo_addRemind);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		Glide.with(mContext).load(list.get(position).getImgurl()
				+ "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png").
				asBitmap().centerCrop().placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
				.into(new MyBitmapImageViewTarget(holder.img));
		int status=list.get(position).getStatus();
		switch (status) {
		case 0:
			holder.state.setText("已结束");
			holder.previewTime.setText("拍卖时间："+list.get(position).getStart_time()+"-"+list.get(position).getEnd_time());
			break;
		case 1:
			holder.state.setText("待预展");
			holder.previewTime.setText("预展时间："+list.get(position).getStart_time()+"-"+list.get(position).getEnd_time());
			break;
		case 2:
			holder.state.setText("预展中");
			holder.previewTime.setText("预展时间："+list.get(position).getStart_time()+"-"+list.get(position).getEnd_time());
			break;
		case 3:
			holder.state.setText("拍卖中");
			holder.previewTime.setText("拍卖时间："+list.get(position).getStart_time()+"-"+list.get(position).getEnd_time());
			break;
		default:
			break;
		}
		holder.title.setText(list.get(position).getTitle());
		holder.num.setText(list.get(position).getLotrecord_num()+"件备案 / "+list.get(position).getLot_num()+"拍品");
		holder.company.setText(list.get(position).getSeller_name());
		holder.address.setText(list.get(position).getAddress());

		final int is_remind=list.get(position).getIs_remind();
		switch (is_remind) {
		case 0:
			//0 已经开拍，不能点击
			holder.addRemind.setVisibility(View.INVISIBLE);
			break;
		case 1:
			//1.添加
			holder.addRemind.setText("添加提醒");
			holder.addRemind.setVisibility(View.VISIBLE);
			break;
		case 2:
			//2. 查看提醒
			holder.addRemind.setText("查看提醒");
			holder.addRemind.setVisibility(View.VISIBLE);
			break;
		default:
			break;
		}
		holder.addRemind.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//提醒按钮
				SpecialInfoParser mSpecialInfoParser=new SpecialInfoParser();
				mSpecialInfoParser.setAddress(list.get(position).getAddress());
				mSpecialInfoParser.setAuction_address(list.get(position).getAuction_address());
				mSpecialInfoParser.setEnd_time(list.get(position).getEnd_time());
				mSpecialInfoParser.setId(list.get(position).getId());
				mSpecialInfoParser.setImgurl(list.get(position).getImgurl());
				mSpecialInfoParser.setIs_remind(list.get(position).getIs_remind());
				mSpecialInfoParser.setLot_num(list.get(position).getLot_num());
				mSpecialInfoParser.setLotrecord_num(list.get(position).getLotrecord_num());
				mSpecialInfoParser.setPreview_address(list.get(position).getPreview_address());
				mSpecialInfoParser.setSeller_name(list.get(position).getSeller_name());
				mSpecialInfoParser.setStart_time(list.get(position).getStart_time());
				mSpecialInfoParser.setStatus(list.get(position).getStatus());
				mSpecialInfoParser.setTitle(list.get(position).getTitle());
				Intent i=new Intent(mContext,AuctionAddRemind_Activity.class);
				i.putExtra("SpecialInfoParser", mSpecialInfoParser);
				mContext.startActivity(i);
			}
		});
		return v;
	}
	class ViewHolder {
		ImageView img;
		TextView state,title,previewTime,num,company,address,addRemind;
	}
}
